﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using CarFrameWork.Common;
using CarFrameWork.Model;
namespace CarFrameWork.Model.CanShuHua
{
	/// <summary>
	/// 类半轴。
	/// </summary>
	[Serializable]
	public partial class 半轴
	{
		public 半轴()
		{}
		#region Model
		private int _id;
		private string _name;
		private string _path;
		private float _d1;
		private float _d6;
		private float _d8;
		private float _d9;
		private float _d10;
		private float _d11;
		private float _d12;
		private float _d19;
		private float _d20;
		private float _d21;
		/// <summary>
		/// 
		/// </summary>
		public int ID
		{
			set{ _id=value;}
			get{return _id;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string name
		{
			set{ _name=value;}
			get{return _name;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string path
		{
			set{ _path=value;}
			get{return _path;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D1
		{
			set{ _d1=value;}
			get{return _d1;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D6
		{
			set{ _d6=value;}
			get{return _d6;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D8
		{
			set{ _d8=value;}
			get{return _d8;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D9
		{
			set{ _d9=value;}
			get{return _d9;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D10
		{
			set{ _d10=value;}
			get{return _d10;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D11
		{
			set{ _d11=value;}
			get{return _d11;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D12
		{
			set{ _d12=value;}
			get{return _d12;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D19
		{
			set{ _d19=value;}
			get{return _d19;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D20
		{
			set{ _d20=value;}
			get{return _d20;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float D21
		{
			set{ _d21=value;}
			get{return _d21;}
		}
		#endregion Model


		#region  Method

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public 半轴(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,name,path,D1,D6,D8,D9,D10,D11,D12,D19,D20,D21 ");
			strSql.Append(" FROM [半轴] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					this.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["name"]!=null && ds.Tables[0].Rows[0]["name"].ToString()!="")
				{
					this.name=ds.Tables[0].Rows[0]["name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["path"]!=null && ds.Tables[0].Rows[0]["path"].ToString()!="")
				{
					this.path=ds.Tables[0].Rows[0]["path"].ToString();
				}
				if(ds.Tables[0].Rows[0]["D1"]!=null && ds.Tables[0].Rows[0]["D1"].ToString()!="")
				{
					this.D1=float.Parse(ds.Tables[0].Rows[0]["D1"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D6"]!=null && ds.Tables[0].Rows[0]["D6"].ToString()!="")
				{
					this.D6=float.Parse(ds.Tables[0].Rows[0]["D6"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D8"]!=null && ds.Tables[0].Rows[0]["D8"].ToString()!="")
				{
					this.D8=float.Parse(ds.Tables[0].Rows[0]["D8"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D9"]!=null && ds.Tables[0].Rows[0]["D9"].ToString()!="")
				{
					this.D9=float.Parse(ds.Tables[0].Rows[0]["D9"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D10"]!=null && ds.Tables[0].Rows[0]["D10"].ToString()!="")
				{
					this.D10=float.Parse(ds.Tables[0].Rows[0]["D10"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D11"]!=null && ds.Tables[0].Rows[0]["D11"].ToString()!="")
				{
					this.D11=float.Parse(ds.Tables[0].Rows[0]["D11"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D12"]!=null && ds.Tables[0].Rows[0]["D12"].ToString()!="")
				{
					this.D12=float.Parse(ds.Tables[0].Rows[0]["D12"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D19"]!=null && ds.Tables[0].Rows[0]["D19"].ToString()!="")
				{
					this.D19=float.Parse(ds.Tables[0].Rows[0]["D19"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D20"]!=null && ds.Tables[0].Rows[0]["D20"].ToString()!="")
				{
					this.D20=float.Parse(ds.Tables[0].Rows[0]["D20"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D21"]!=null && ds.Tables[0].Rows[0]["D21"].ToString()!="")
				{
					this.D21=float.Parse(ds.Tables[0].Rows[0]["D21"].ToString());
				}
			}
		}

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{

		return DbHelperSQL.GetMaxID("ID", "半轴"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from [半轴]");
			strSql.Append(" where ID=@ID ");

			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into [半轴] (");
			strSql.Append("name,path,D1,D6,D8,D9,D10,D11,D12,D19,D20,D21)");
			strSql.Append(" values (");
			strSql.Append("@name,@path,@D1,@D6,@D8,@D9,@D10,@D11,@D12,@D19,@D20,@D21)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@name", SqlDbType.NVarChar,50),
					new SqlParameter("@path", SqlDbType.NVarChar),
					new SqlParameter("@D1", SqlDbType.Float,8),
					new SqlParameter("@D6", SqlDbType.Float,8),
					new SqlParameter("@D8", SqlDbType.Float,8),
					new SqlParameter("@D9", SqlDbType.Float,8),
					new SqlParameter("@D10", SqlDbType.Float,8),
					new SqlParameter("@D11", SqlDbType.Float,8),
					new SqlParameter("@D12", SqlDbType.Float,8),
					new SqlParameter("@D19", SqlDbType.Float,8),
					new SqlParameter("@D20", SqlDbType.Float,8),
					new SqlParameter("@D21", SqlDbType.Float,8)};
			parameters[0].Value = name;
			parameters[1].Value = path;
			parameters[2].Value = D1;
			parameters[3].Value = D6;
			parameters[4].Value = D8;
			parameters[5].Value = D9;
			parameters[6].Value = D10;
			parameters[7].Value = D11;
			parameters[8].Value = D12;
			parameters[9].Value = D19;
			parameters[10].Value = D20;
			parameters[11].Value = D21;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update [半轴] set ");
			strSql.Append("name=@name,");
			strSql.Append("path=@path,");
			strSql.Append("D1=@D1,");
			strSql.Append("D6=@D6,");
			strSql.Append("D8=@D8,");
			strSql.Append("D9=@D9,");
			strSql.Append("D10=@D10,");
			strSql.Append("D11=@D11,");
			strSql.Append("D12=@D12,");
			strSql.Append("D19=@D19,");
			strSql.Append("D20=@D20,");
			strSql.Append("D21=@D21");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@name", SqlDbType.NVarChar,50),
					new SqlParameter("@path", SqlDbType.NVarChar),
					new SqlParameter("@D1", SqlDbType.Float,8),
					new SqlParameter("@D6", SqlDbType.Float,8),
					new SqlParameter("@D8", SqlDbType.Float,8),
					new SqlParameter("@D9", SqlDbType.Float,8),
					new SqlParameter("@D10", SqlDbType.Float,8),
					new SqlParameter("@D11", SqlDbType.Float,8),
					new SqlParameter("@D12", SqlDbType.Float,8),
					new SqlParameter("@D19", SqlDbType.Float,8),
					new SqlParameter("@D20", SqlDbType.Float,8),
					new SqlParameter("@D21", SqlDbType.Float,8),
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = name;
			parameters[1].Value = path;
			parameters[2].Value = D1;
			parameters[3].Value = D6;
			parameters[4].Value = D8;
			parameters[5].Value = D9;
			parameters[6].Value = D10;
			parameters[7].Value = D11;
			parameters[8].Value = D12;
			parameters[9].Value = D19;
			parameters[10].Value = D20;
			parameters[11].Value = D21;
			parameters[12].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from [半轴] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public void GetModel(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,name,path,D1,D6,D8,D9,D10,D11,D12,D19,D20,D21 ");
			strSql.Append(" FROM [半轴] ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.Int,4)};
			parameters[0].Value = ID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					this.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["name"]!=null && ds.Tables[0].Rows[0]["name"].ToString()!="")
				{
					this.name=ds.Tables[0].Rows[0]["name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["path"]!=null && ds.Tables[0].Rows[0]["path"].ToString()!="")
				{
					this.path=ds.Tables[0].Rows[0]["path"].ToString();
				}
				if(ds.Tables[0].Rows[0]["D1"]!=null && ds.Tables[0].Rows[0]["D1"].ToString()!="")
				{
					this.D1=float.Parse(ds.Tables[0].Rows[0]["D1"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D6"]!=null && ds.Tables[0].Rows[0]["D6"].ToString()!="")
				{
					this.D6=float.Parse(ds.Tables[0].Rows[0]["D6"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D8"]!=null && ds.Tables[0].Rows[0]["D8"].ToString()!="")
				{
					this.D8=float.Parse(ds.Tables[0].Rows[0]["D8"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D9"]!=null && ds.Tables[0].Rows[0]["D9"].ToString()!="")
				{
					this.D9=float.Parse(ds.Tables[0].Rows[0]["D9"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D10"]!=null && ds.Tables[0].Rows[0]["D10"].ToString()!="")
				{
					this.D10=float.Parse(ds.Tables[0].Rows[0]["D10"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D11"]!=null && ds.Tables[0].Rows[0]["D11"].ToString()!="")
				{
					this.D11=float.Parse(ds.Tables[0].Rows[0]["D11"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D12"]!=null && ds.Tables[0].Rows[0]["D12"].ToString()!="")
				{
					this.D12=float.Parse(ds.Tables[0].Rows[0]["D12"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D19"]!=null && ds.Tables[0].Rows[0]["D19"].ToString()!="")
				{
					this.D19=float.Parse(ds.Tables[0].Rows[0]["D19"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D20"]!=null && ds.Tables[0].Rows[0]["D20"].ToString()!="")
				{
					this.D20=float.Parse(ds.Tables[0].Rows[0]["D20"].ToString());
				}
				if(ds.Tables[0].Rows[0]["D21"]!=null && ds.Tables[0].Rows[0]["D21"].ToString()!="")
				{
					this.D21=float.Parse(ds.Tables[0].Rows[0]["D21"].ToString());
				}
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM [半轴] ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		#endregion  Method
	}
}

